# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    def reverseList(self, head: ListNode) -> ListNode:
        # 终止条件是当前节点或者下一个节点==null
        # 在函数内部，改变节点的指向，也就是 head 的下一个节点指向 head 递归函数那句
        if not head or not head.next:
            return head 
        nextNode = self.reverseList(head.next)
        head.next.next = head # head 的下一个节点指向head
        head.next = None
        return nextNode
       